#ifndef MPVPLAYER_H
#define MPVPLAYER_H

#include <QObject>
#include "client.h"

class MpvPlayer : public QObject
{
    Q_OBJECT
public:
    explicit MpvPlayer(QWidget* videoRenderWnd = nullptr, QObject *parent = nullptr);
    ~MpvPlayer();

    void startPlay(const QString& videoPath);

    void play();

    void pause();

    void setPlaySpeed(double speed);

    void setVolume(int64_t volume);

    void setCurrentPlayPosition(int64_t poition);

    int64_t getPlayTime();

    // 获取视频首帧图
    static QString getVideoFirstFrame(const QString& videoPath);

private:
    void onMpvEvents();

    void handleMpvEvent(mpv_event* event);
signals:
    void mpvEvents();

    void playPositionChanged(int64_t curPlayTime);

    void endOfPlaylist();

    // 视频总时⻓发⽣改变时
    void durationChanged(int64_t duration);

private:
    //mpv句柄
    mpv_handle* mpv = nullptr;
    // 保存整个视频的当前播放时间
    int64_t curPlayTime;
};

#endif // MPVPLAYER_H
